package com.taxigang.client;

/*
 * TODO
 * Pressing MyTaxiGangs shows nothing when empty
 * Error in expiring TaxiGangs
 * SignOut Button needs correction
 *
 * Admin Panel
 * 			Feedbacks need a read field
 * Feebback
 *       Cancel button does not return to home
 * Home Panel
 *       Reset utton to enter new searches
 *
 * List Taxi Gangs
 *    - show departure time as day eg. "tuesday"
 *    - affinity always shows 0
 *
 * New panel "Settings"
 * 	  - change display name
 *    - home town
 *
 * Database
 *    - search for TaxiGangs should return only those in a given distance from the start address
 *
 */


import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.taxigang.client.Authenication.Provider;
import com.taxigang.client.Authenication.Status;
import com.taxigang.client.micro.TaxiGangCreator;
import com.taxigang.client.ui.map.ProcessingDialog;
import com.taxigang.client.uibinder.Alert;
import com.taxigang.client.uibinder.TaxiGangPresenter;
import com.taxigang.shared.AmbassadorResponseInfo;
import com.taxigang.shared.ChitInfo;
import com.taxigang.shared.ContactInfo;
import com.taxigang.shared.LoginInfo;
import com.taxigang.shared.RouteInfo;
import com.taxigang.shared.TaxiCompanyInfo;
import com.taxigang.shared.TaxiGangInfo;
import com.taxigang.shared.TaxiGanguserInfo;
import com.taxigang.shared.TaxiGangInfo.LeaveResult;


/**
 * Provides responses for queries made to the SuggestBox
 */

public class TaxiGangHandler implements TaxiGangBus{
	public enum Success{NONE, UPDATE ,JOIN, CREATE};
	public enum Crud{CREATE,REPLACE,UPDATE,DELETE};


	private final TaxiGangServiceAsync taxigangService = GWT.create(TaxiGangService.class);
	private final LoginServiceAsync loginService = GWT.create(LoginService.class);
	//private final TaxiGangImageBundle tgib = (TaxiGangImageBundle)GWT.create(TaxiGangImageBundle.class);
	//	private MyTaxiGangsPresenter myTaxiGangsPresenter;
	//	private AdminPresenter adminPresenter;
	//	private MessagePresenter messagePresenter;
	//	private WelcomePresenter welcomePresenter;
	//	private CreatePresenter createPresenter;


	//private boolean online=true;
	public static DateTimeFormat formatter = DateTimeFormat.getFormat("EEE, MMM d, hh:mm a");

	private static TaxiGangHandler instance = new TaxiGangHandler();

	public static TaxiGangHandler getInstance(){
		return instance;
	}


	//	public void setPresenter(WelcomePresenter welcomePresenter, AdminPresenter adminPresenter){
	//		//this.welcomePresenter = welcomePresenter;		
	//		this.adminPresenter = adminPresenter;		
	//	}


	public void addMessage(final TaxiGangInfo taxiganginfo, String message){
		final Session session = Session.getInstance();
		taxigangService.addMessage(taxiganginfo, session.getLoginInfo(), message ,new AsyncCallback<Void>() {
			public void onFailure(Throwable error) {
				showSorry("add message");
			}
			public void onSuccess(Void v) {
				taxigangService.getMyTaxiGangs(session.getLoginInfo(), new AsyncCallback<TaxiGangInfo[]>() {
					public void onFailure(Throwable error) {
						showSorry("get my taxigangs during add message");
					}
					public void onSuccess(TaxiGangInfo[] taxigangInfoList) {
						session.setMyTaxiGangInfoList(taxigangInfoList);
						session.setCurrentMyTaxiGang(taxiganginfo);
						TaxiGangPresenter.getInstance().displayMessages();
					}
				});


			}
		});
	}

	public void clickedToDeleteClosedTaxiGang(TaxiGangInfo taxiganginfo){
		taxigangService.deleteTaxiGang(taxiganginfo, new AsyncCallback<Void>() {
			public void onFailure(Throwable error) {
				showSorry("clickedToDeleteClosedTaxiGang");
			}
			public void onSuccess(Void v) {
				//displayMyTaxiGangsList();
				//tabPanel.selectTab(1);

			}
		});
	}


	public String invitationMessage(){
		String msgBody = TaxiGangCreator.taxiGangConstants.invitationGreeting()+"\n";;
		msgBody += TaxiGangCreator.taxiGangConstants.from()+":"+"***START***"+"\n";
		msgBody += TaxiGangCreator.taxiGangConstants.to()+":"+"***DESTINATION***"+"\n";
		msgBody += TaxiGangCreator.taxiGangConstants.time()+":"+"***TIME***"+"\n";
		msgBody += TaxiGangCreator.taxiGangConstants.invitationLink()+"\n\n";
		return msgBody;
	}


	public void createTaxiGang(ChitInfo info){
		Log.info("TaxigangPresenter:createTaxiGang:"+info.getChitText());
		
		final Session session = Session.getInstance();
		TaxiGangInfo taxiGangInfo = session.getSearchTaxiGangInfo();
		String invitationMessage = invitationMessage();

		taxiGangInfo.setInvitationMessage(invitationMessage);
		Log.info("TaxigangPresenter:createTaxiGang:"+taxiGangInfo.getDepartureHour()+":"+taxiGangInfo.getDepartureMinute());
		LoginInfo loginInfo = session.getLoginInfo();
		taxigangService.createTaxiGang(taxiGangInfo, loginInfo,info, new AsyncCallback<TaxiGangInfo>() {
			public void onFailure(Throwable error) {
				showSorry("createTaxiGang");
			}
			public void onSuccess(TaxiGangInfo taxiGangInfo) {
				searchForMyTaxiGangs(Success.CREATE, taxiGangInfo);
			}
		});
	}

	public void joinTaxiGang(ChitInfo chitInfo){
		final Session session = Session.getInstance();
		final TaxiGangInfo taxiGangInfo = session.getJoinTaxiGangInfo();
		taxigangService.joinTaxiGang(taxiGangInfo, session.getLoginInfo(), chitInfo ,new AsyncCallback<Void>() {
			public void onFailure(Throwable error) {
				showSorry("joinTaxiGang");
			}
			public void onSuccess(Void v) {
				searchForMyTaxiGangs(Success.JOIN,taxiGangInfo);
				//tabPanel.selectTab(1);
			}
		});
	}

	private void listenForUpdates(String channelId){
		if (!TaxiGangMain.channelSupported){
			return;
		}
//		Log.info("channelId:"+channelId);
//		try{
//			Channel channel = ChannelFactory.createChannel(channelId);
//			//
//			//	    // The 'Game' object exposes a method which creates a unique string based on the game's key
//			//	    // and the user's id.
//			//	    String token = channelService.createChannel(taxigang.getChannelKey(userId));
//			// Open the channel and attach a listener.
//			channel.open(new SocketListener() {
//				@Override
//				public void onOpen() {
//					// Alert when the channel opens.
//					//Window.alert("Channel opened");
//					Log.info("Channel opened");
//				}
//				@Override
//				public void onMessage(String message) {
//					// Alert when the channel receives a message.
//					Log.info("update message received"+message);
//					String sender = message.substring(message.indexOf(":")+1);
//					String myId = Session.getInstance().getLoginInfo().getId();
//					Log.info("sender="+sender+"  myId="+myId);
//					if (sender!=null && !sender.trim().equals(myId.trim())){
//						String operation = message.substring(0, message.indexOf(":"));
//						String title = TaxiGangCreator.taxiGangConstants.news();
//						String text = "";
//						if ("JOIN".equals(operation)){
//							text = TaxiGangCreator.taxiGangConstants.taxigangWasJoined();
//						}
//						if ("LEAVE".equals(operation)){
//							text = TaxiGangCreator.taxiGangConstants.taxigangWasLeft();
//						}
//						if ("MESSAGE".equals(operation)){
//							text = TaxiGangCreator.taxiGangConstants.aNewMessage();
//						}
//						Alert.alert(null,title,text,false);
//						//Window.alert(message+"\r"+sender+"\r"+Session.getInstance().getLoginInfo().getId());
//						searchForMyTaxiGangs(Success.UPDATE,null);
//					}
//
//				}
//			});
//
//		} catch (Exception ex){
//			Log.error(ex.getMessage());
//		}
//		//}

	}


	public void searchForTaxiGangs( ){
		final Session session = Session.getInstance();

		TaxiGangInfo taxiganginfo = session.getSearchTaxiGangInfo();

		taxigangService.getTaxiGangs(taxiganginfo, new AsyncCallback<TaxiGangInfo[]>() {
			public void onFailure(Throwable error) {
				showSorry("searchForTaxiGangs");
			}
			public void onSuccess(TaxiGangInfo[] taxigangInfoList) {
				session.setTaxiGangSearchResultList(taxigangInfoList);
				TaxiGangPresenter.getInstance().displayTaxiGangsList();

			}
		});

	}




	public void leaveTaxiGang(boolean confirm){
		if (!confirm){
			Command cmd = new Command(){
				public void execute(){
					TaxiGangHandler.getInstance().leaveTaxiGang(true);
				}
			};
			Alert.alert(cmd,TaxiGangCreator.taxiGangConstants.leave()+ "Taxigang",TaxiGangCreator.taxiGangConstants.reallyWantToLeave(),true,"422px");

			return;
		}
		final Session session = Session.getInstance();
		taxigangService.leaveTaxiGang(session.getCurrentMyTaxiGang(), session.getLoginInfo(), new AsyncCallback<LeaveResult>() {
			public void onFailure(Throwable error) {
				showSorry("leaveTaxiGang");
			}
			public void onSuccess(LeaveResult leaveResult) {
				switch (leaveResult){
				case OK : searchForMyTaxiGangs(Success.NONE,null);
				break;
				case CANT_LEAVE : TaxiGangPresenter.getInstance().showCantLeave();
				break;
				}
			}
		});

	}

	public void award() {
		final Session session = Session.getInstance();
		taxigangService.award(session.getCurrentMyTaxiGang(), session.getLoginInfo(), new AsyncCallback<Void>() {
			public void onFailure(Throwable error) {
				showSorry("leaveTaxiGang");
			}
			public void onSuccess(Void leaveResult) {
				searchForMyTaxiGangs(Success.NONE,null);
			}
		});
		
	}

	public void deleteTaxiGang(boolean confirm){
		if (!confirm){
			Command cmd = new Command(){
				public void execute(){
					TaxiGangHandler.getInstance().deleteTaxiGang(true);
				}
			};
			Alert.alert(cmd,TaxiGangCreator.taxiGangConstants.delete()+ "Taxigang",TaxiGangCreator.taxiGangConstants.reallyWantToDelete(),true,"422px");

			return;
		}
		final Session session = Session.getInstance();
		taxigangService.deleteTaxiGang(session.getCurrentMyTaxiGang(),new AsyncCallback<Void>() {
			public void onFailure(Throwable error) {
				showSorry("deleteTaxiGang");
			}
			public void onSuccess(Void v) {
				searchForMyTaxiGangs(Success.NONE,null);
			}
		});

	}

	public void searchForMyTaxiGangs(final Success success, final TaxiGangInfo myCurrentTaxiGang){
		ProcessingDialog.show(TaxiGangCreator.taxiGangConstants.processing());
		Log.info("TaxiGangHandler:searchForMyTaxiGangs");
		final Session session = Session.getInstance();
		TaxiGanguserInfo taxiGanguserInfo = session.getTaxiGangUserInfo();
		if (taxiGanguserInfo != null){
			session.getLoginInfo().setId(taxiGanguserInfo.getId());
			Log.info("searchForMyTaxiGangs uid="+session.getLoginInfo().getId()+" "+taxiGanguserInfo.getDisplayName());
			taxigangService.getMyTaxiGangs(session.getLoginInfo(), new AsyncCallback<TaxiGangInfo[]>() {
				public void onFailure(Throwable error) {
					ProcessingDialog.hide();					
					showSorry("searchForMyTaxiGangs:"+success);
				}
				public void onSuccess(TaxiGangInfo[] taxigangInfoList) {
					ProcessingDialog.hide();					
					Log.info("searchForMyTaxiGangs no. of my taxigangs ="+taxigangInfoList.length);
					if (taxigangInfoList.length > 0){
						Log.info("searchForMyTaxiGangs id of first ="+taxigangInfoList[0].getId());
					}
					session.setMyTaxiGangInfoList(taxigangInfoList);
					if (myCurrentTaxiGang != null){
						session.setCurrentMyTaxiGang(myCurrentTaxiGang);
					}
					TaxiGangPresenter.getInstance().displayMyTaxiGangsList();
					TaxiGangPresenter.getInstance().showSuccess(success);
				}
			});
		}else{
			Log.error("searchForMyTaxiGangs but taxiGanguserInfo is null!");
		}

	}

	public void deleteAllTaxiGangs() {
		taxigangService.deleteAllTaxiGangs(new AsyncCallback<Void>() {
			public void onFailure(Throwable error) {
				showSorry("deleteAllTaxiGangs");
			}
			public void onSuccess(Void v) {
				Window.alert("deleted all tagigangs");
			}
		});
	}

	@Override
	public void getTemporyTaxiGangUser(){
		final Session session = Session.getInstance();

		taxigangService.getTaxiGangUser(session.getLoginInfo(), new AsyncCallback<TaxiGanguserInfo>() {
			public void onFailure(Throwable error) {
				//Window.alert("getTaxiGangUser problem");
				Log.error(error.getMessage());
			}
			public void onSuccess(TaxiGanguserInfo taxigangUserInfo) {
				Log.info("getTemporyTaxiGangUser:returned:"+taxigangUserInfo.getId());
				switch (taxigangUserInfo.getStatus()){
				case OK: 
					Log.info("returned:"+taxigangUserInfo.getStatus());
					session.setTaxiGangUserInfo(taxigangUserInfo);
					session.getLoginInfo().setId(taxigangUserInfo.getId());

					String TAXIGANG_COM = "http://www.taxigang.com/";
					String locale = Session.getInstance().getLocale();
					if(locale != null && !locale.trim().isEmpty()){
						TAXIGANG_COM +="?locale="+locale;
					}
					TaxiGangProcessor.signOutLink.setHref(TAXIGANG_COM);

					//welcomePresenter.onTempLogin();
					Authenication.getInstance().getLogedinResolved(Provider.TEMP, Status.LoggedIn);
					break;
				case USERNAME_INUSE: 
					Window.alert("username in use or wrong password");
					break;
				default:
					Log.error("unexpected:"+taxigangUserInfo.getStatus());
				}
			}
		});
	}


	public void loginToGoogle(String uri){
		Log.info("loginToGoogle with url: "+ uri);
		loginService.login(uri, new AsyncCallback<LoginInfo>() {
			public void onFailure(Throwable error) {
				Window.alert("login problem:"+error.getMessage());
			}
			public void onSuccess(LoginInfo loginInfo) {
				Log.info("loginToGoogle: onSuccess: "+ loginInfo.isLoggedIn());
				Authenication authentication = Authenication.getInstance();
				Status status = Status.LoggedOut;
				if (loginInfo.isLoggedIn()){
					if (authentication.getLoggedoutResolved(Provider.Google, Status.LoggedIn)){					
						Log.info("loginToGoogle:loggedinresolved:google");
						Session.getInstance().setLoginInfo(loginInfo); 
						TaxiGangPresenter.getInstance().authenticationComplete(true);

						Log.info("loginToGoogle:loggedoutresolved:google complete");				
					}

				} else {
					if (authentication.getLoggedoutResolved(Provider.Google, Status.LoggedOut)){					
						Log.info("loginToGoogle:loggedoutresolved:google");
						//Window.alert ("fb resolved: "+result);
						//Window.alert ( "not logged in - show login" );
						Session.getInstance().setLoginInfo(loginInfo); 
						TaxiGangPresenter.getInstance().authenticationComplete(true);

						Log.info("loginToGoogle:loggedoutresolved:google complete");
					} else {
						Log.info("loginToGoogle:onSuccess: !loggedoutresolved:google");					
					}

				}
				authentication.setAuthStatus(Provider.Google, status);
				//				Log.info("getTaxiGangUser:"+loginInfo.isLoggedIn());
				//				if (welcomePresenter==null){
				//					Log.error("welcomePresenter is null");
				//				}else{
				//					Session session = Session.getInstance();
				//					session.setLoginInfo(loginInfo);
				//					welcomePresenter.handleGoogleResponse(loginInfo);
				//				}
			}
		});

	}

	@Override
	public void getTaxiGangUser(){
		final Session session = Session.getInstance();
		Log.info("getTaxiGangUser:"+session.getLoginInfo().getId());
		taxigangService.getTaxiGangUser(session.getLoginInfo(), new AsyncCallback<TaxiGanguserInfo>() {
			public void onFailure(Throwable error) {
				showSorry("getTaxiGangUser problem: "+session.getLoginInfo().getId());
			}
			public void onSuccess(TaxiGanguserInfo taxigangUserInfo) {
				Log.info("getTaxiGangUser:"+taxigangUserInfo);
				listenForUpdates(taxigangUserInfo.getChannelToken());
				logInfo("LOGIN:"+taxigangUserInfo.getDisplayName());
				session.setTaxiGangUserInfo(taxigangUserInfo);
				//TaxiGangPresenter.getInstance().initOracle();
				//welcomePresenter.handleGotUser(taxigangUserInfo);
				//searchForMyTaxiGangs(Success.NONE);

			}
		});

	}

	public void showInvitation() {
		final Session session = Session.getInstance();
		Log.info("showInvitation:"+session.getRef());
		taxigangService.getInvitation(session.getRef(), new AsyncCallback<TaxiGangInfo>() {
			public void onFailure(Throwable error) {
				showSorry("getTaxiGangUser problem: "+session.getLoginInfo().getId());
			}
			public void onSuccess(TaxiGangInfo taxigangInfo) {
				if (taxigangInfo!=null){
					TaxiGangInfo[]resultSearchList = {taxigangInfo};
					session.setTaxiGangSearchResultList(resultSearchList);
				}else{
					TaxiGangInfo[]resultSearchList = {};
					session.setTaxiGangSearchResultList(resultSearchList);					
				}
				TaxiGangPresenter.getInstance().displayTaxiGangsList();
			}
		});

	}
	public void getPartner(final String partnerRef,final Command cmd) {
		Log.info("showPartner:"+partnerRef);
		taxigangService.getPartner(partnerRef, new AsyncCallback<RouteInfo>() {
			public void onFailure(Throwable error) {
				showSorry("getPartner problem: "+ partnerRef);
			}
			public void onSuccess(RouteInfo partnerInfo) {
//				partnerInfo = new PartnerInfo();
//				partnerInfo.setLat(48);
//				partnerInfo.setLng(11);
				Session.getInstance().setRoute(partnerInfo);
				cmd.execute();
			}
		});

	}
	public void getRoute(final String ref,final Command cmd) {
		Log.info("getRoute:"+ref);
		taxigangService.getRoute(ref, new AsyncCallback<RouteInfo>() {
			public void onFailure(Throwable error) {
				showSorry("getPartner problem: "+ ref);
			}
			public void onSuccess(RouteInfo routeInfo) {
//				partnerInfo = new PartnerInfo();
//				partnerInfo.setLat(48);
//				partnerInfo.setLng(11);
				Session.getInstance().setRoute(routeInfo);
				cmd.execute();
			}
		});

	}
	public void showWishRouteCancel() {
		final Session session = Session.getInstance();
		Log.info("showWishRouteCancel:"+session.getWishRouteCancel());
		taxigangService.cancelWishRoute(session.getWishRouteCancel(), new AsyncCallback<Void>() {
			public void onFailure(Throwable error) {
				showSorry("getTaxiGangUser problem: "+session.getLoginInfo().getId());
			}
			public void onSuccess(Void v) {
				
				Window.alert("Wish route cancelled");
				ProcessingDialog.hide();

			}
		});

	}

	
	
	public void logInfo(String infoMessage){
		taxigangService.logInfo(infoMessage, new AsyncCallback<Void>() {
			public void onFailure(Throwable error) {
				showSorry("getTaxiGangUser problem: ");
			}
			public void onSuccess(Void v) {
				//searchForMyTaxiGangs();
				//tabPanel.selectTab(1);
			}
		});
	}

	//	public void crudAdmin(Crud crud, BaseModel model){
	//		taxigangService.crudAdmin(crud, model, new AsyncCallback<BaseModel[]>() {
	//			public void onFailure(Throwable error) {
	//				Window.alert("logging problem");
	//			}
	//			public void onSuccess(BaseModel[] l) {
	//			}
	//		});
	//	}

	//	public void getTaxiCompanies(final String postalCode){
	//		taxigangService.getTaxiCompanies(postalCode, new AsyncCallback<TaxiCompanyInfo[]>() {
	//			public void onFailure(Throwable error) {
	//				Window.alert("getTaxiCompanies problem");
	//			}
	//			public void onSuccess(TaxiCompanyInfo[] l) {
	//				TaxiGangPresenter.getInstance().updateTaxiCompanies(postalCode,l);
	//				//createPresenter.updateTaxiCompanies(postalCode,l);
	//			}
	//		});
	//	}

	private void showSorry(String operation){
		Log.error("Error in TaxiGangHandler:"+operation);
		Alert.alert(null, "Problem", TaxiGangCreator.taxiGangConstants.sorryProblem(), false,"422px");
	}


	public void sendAmbassadorResponse(AmbassadorResponseInfo info) {
		taxigangService.sendAmbassadorResponse(info, new AsyncCallback<Void>() {
			public void onFailure(Throwable error) {
				showSorry("getTaxiGangUser problem: ");
			}
			public void onSuccess(Void v) {
				//searchForMyTaxiGangs();
				//tabPanel.selectTab(1);
			}
		});
		
	}

	public void createWishRoute(){
		TaxiGangInfo taxiGangInfo = Session.getInstance().getSearchTaxiGangInfo();
		LoginInfo loginInfo = Session.getInstance().getLoginInfo();
		taxigangService.createWishRoute(taxiGangInfo, loginInfo,new AsyncCallback<Void>() {
			public void onFailure(Throwable error) {
				showSorry("getTaxiGangUser problem: ");
			}
			public void onSuccess(Void v) {
				//searchForMyTaxiGangs();
				//tabPanel.selectTab(1);
			}
		});
		
	}

	public void getTaxiCompany(TaxiGangInfo taxiGangInfo){
		taxigangService.findTaxiCompanies(taxiGangInfo, new AsyncCallback<TaxiCompanyInfo[]>() {
			public void onFailure(Throwable error) {
				showSorry("getTaxiGangUser problem: ");
			}
			public void onSuccess(TaxiCompanyInfo[] listTaxiCompanies) {
				
//				TaxiCompanyInfo taxiCompanyInfo1 =  new TaxiCompanyInfo();
//				taxiCompanyInfo1.setName("TaxiCompany A");
//				taxiCompanyInfo1.setTelAreaCode("089");
//				taxiCompanyInfo1.setTelNo("11111");
//
//				TaxiCompanyInfo taxiCompanyInfo2 =  new TaxiCompanyInfo();
//				taxiCompanyInfo2.setUrl("http://www.yellowcabaustin.com/order.aspx");
//				taxiCompanyInfo2.setName("TaxiCompany B");
//				TaxiCompanyInfo taxiCompanyInfo3 =  new TaxiCompanyInfo();
//				taxiCompanyInfo3.setName("TaxiCompany C");
//				taxiCompanyInfo3.setTelAreaCode("089");
//				taxiCompanyInfo3.setTelNo("222222");
//				TaxiCompanyInfo taxiCompanyInfo4 =  new TaxiCompanyInfo();
//				taxiCompanyInfo4.setName("TaxiCompany D");
//				taxiCompanyInfo4.setUrl("http://www.yellowcabaustin.com/order.aspx");
//				TaxiCompanyInfo taxiCompanyInfo5 =  new TaxiCompanyInfo();
//				taxiCompanyInfo5.setName("TaxiCompany D");
//				taxiCompanyInfo5.setTelAreaCode("089");
//				taxiCompanyInfo5.setTelNo("555555");
//				
//				listTaxiCompanies = new TaxiCompanyInfo[]{taxiCompanyInfo1,taxiCompanyInfo2,taxiCompanyInfo3,taxiCompanyInfo4,taxiCompanyInfo5};

				TaxiGangPresenter.getInstance().displayTaxiCompanyList(listTaxiCompanies);
			}
		});
		
	}

	public void sendContactInfo(ContactInfo info) {
		taxigangService.sendContactInfo(info, new AsyncCallback<Void>() {
			public void onFailure(Throwable error) {
				showSorry("getTaxiGangUser problem: ");
			}
			public void onSuccess(Void v) {
				//searchForMyTaxiGangs();
				//tabPanel.selectTab(1);
			}
		});
		
	}

	public void runCron() {
		String cron = Session.getInstance().getCron();
		taxigangService.runCron(cron, new AsyncCallback<Void>() {
			public void onFailure(Throwable error) {
				showSorry("getTaxiGangUser problem: ");
			}
			public void onSuccess(Void v) {
				//searchForMyTaxiGangs();
				//tabPanel.selectTab(1);
			}
		});
		
	}

}